/*
 * @Author: 飞越疯人院 353362604@qq.com
 * @Date: 2022-11-21 08:37:52
 * @LastEditors: 飞越疯人院 353362604@qq.com
 * @LastEditTime: 2022-11-21 14:00:39
 * @FilePath: \adminstration\src\Common\Modal\MoreModal\FieldConfiguration.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios from 'axios'
import { Descriptions } from 'antd'
import { useState, useEffect, useCallback } from 'react'

export const FieldConfiguration = ({ CurrentData, RefreshEvent }) => {
    const [FormList, setFormList] = useState([])

    const getCurrentData = useCallback(async () => {
        const { get, params } = CurrentData
        const res = await axios.get(get, { params })
        setFormList(res.data)
    }, [CurrentData])

    RefreshEvent.useSubscription(() => getCurrentData())

    useEffect(() => {
        getCurrentData()
    }, [getCurrentData])
    return (
        <div className="FieldConfiguration">
            <div className="options">{FormList && FormList.length !== 0 && CurrentData.option.map(item => item)}</div>
            <Descriptions bordered style={{ width: '100%' }} value="small">
                {FormList &&
                    FormList.length !== 0 &&
                    FormList.map(({ projectFormItemUuid, projectFormItemCode, projectFormItemName, value }) => (
                        <Descriptions.Item key={projectFormItemUuid} label={projectFormItemName}>
                            {(() => {
                                switch (projectFormItemCode) {
                                    case 'scene':
                                        return CurrentData.SceneList[value]
                                    case 'towns':
                                        return CurrentData.ProjectRegion[value]
                                    default:
                                        return value
                                }
                            })()}
                        </Descriptions.Item>
                    ))}
            </Descriptions>
        </div>
    )
}
